/**
 * Copyright 厦门中软海晟信息技术有限公司 版权所有 违者必究 2019
 */
package com.leetCode.structure;

/**
 * @author : sunzb(sunzb@hsit.com.cn)
 * @date: 2019/5/10
 */
public class ListNode {
    public int val;
    public ListNode next = null;

    public ListNode(int x) {
        val = x;
    }

    public static ListNode build(int[] input) {
        int len = input.length;
        ListNode[] listNodes = new ListNode[len];
        listNodes[0] = new ListNode(input[0]);
        for (int i = 1; i < len; i++) {
            listNodes[i] = new ListNode(input[i]);
            listNodes[i - 1].next = listNodes[i];
        }
        return listNodes[0];
    }

    public static String str(ListNode head) {
        StringBuilder sb = new StringBuilder().append('[');
        int times = 0;
        while (head != null && ++times < 20) {
            sb.append(head.val).append(',');
            head = head.next;
        }
        return sb.substring(0, sb.length() - 1) + ']';
    }
}
